home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / bor_ti.exe / TI1155.ASC < prev    next >
Text File  |  1992-11-04  |  4KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1155
  9.   VERSION  :  3.1
  10.        OS  :  DOS
  11.      DATE  :  November 4, 1992                         PAGE  :  1/2
  12.  
  13.     TITLE  :  Detecting unusual keystrokes and key combinations.
  14.  
  15.  
  16.  
  17.  
  18.  
  19.             Detecting unusual keystrokes and key combinations.
  20.             -------------------------------------------------
  21.  
  22.        Some keystrokes, such as CTRL-1, cannot be caught with
  23.   bioskey() or an INT 15,4H interrupt handler because the BIOS does
  24.   not pass the scan code along to INT 15.  If you need to catch
  25.   these keystrokes, you will need to intercept the keystroke
  26.   directly at the INT 9 level.  This example of code demonstrates
  27.   exactly how to catch keystrokes such as CTRL-1.  When the program
  28.   is run, keystrokes will echo the screen as normal, but whenever a
  29.   CTRL-1 is pressed, the machine will beep.
  30.  
  31.   #include <dos.h>
  32.   #include <bios.h>
  33.   #include <stdio.h>
  34.  
  35.   /* 0x02 is the value for 1 */
  36.   #define KEY_TO_CATCH 0x02
  37.  
  38.   /* Old INT 9 handler routine */
  39.   void interrupt ( *Old09Handler )(...);
  40.  
  41.   void interrupt New09Handler(...)
  42.   {
  43.       _AL = inportb( 0x60 );              // Read the Scan Code
  44.       if ( _AL == KEY_TO_CATCH )          // Is it that key?
  45.       {
  46.           _AH = 0x02;                     // Check the Shift
  47.           geninterrupt( 0x16 );           // Status using BIOS
  48.           if ( _AX & 0x04 )               // Is Control Held Down?
  49.           {
  50.               _AL  = inportb( 0x61 );     // Reset the Keyboard
  51.               _AH  = _AL;
  52.               _AL |= 0x80;
  53.               outportb( 0x61, _AL );
  54.               _AL  = _AH;
  55.               outportb( 0x61, _AL );
  56.               outportb( 0x20, 0x20 );     // EOI to 8259
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1155
  75.   VERSION  :  3.1
  76.        OS  :  DOS
  77.      DATE  :  November 4, 1992                         PAGE  :  2/2
  78.  
  79.     TITLE  :  Detecting unusual keystrokes and key combinations.
  80.  
  81.  
  82.  
  83.  
  84.               _AX = 0x0E07;               // Beep to indicate that
  85.               geninterrupt( 0x10 );       // we caught the desired
  86.                                           // key
  87.               return;                     // Do not chain!
  88.           }
  89.       }
  90.       Old09Handler();                     // Chain to Old Handler
  91.   }
  92.  
  93.   int main( void )
  94.   {
  95.       Old09Handler = getvect( 0x09 );     // Save the original
  96.       setvect( 0x09, New09Handler );      // Install new
  97.  
  98.       puts( "Please hit the ESC key to terminate..." );
  99.  
  100.       LABEL:
  101.       asm {
  102.                   mov     ah, 8h
  103.                   int     21h
  104.                   or      al, al
  105.                   jz      LABEL
  106.                   mov     dl, al
  107.                   mov     ah, 2
  108.                   int     21h
  109.                   cmp     dl, 27
  110.                   jne     LABEL
  111.           }
  112.  
  113.       setvect( 0x09, Old09Handler );      // Restore Original
  114.       return( 0 );
  115.   }
  116.  
  117.   /*
  118.   Keywords:  bioskey, CTRL-3, CTRL-4, CTRL-5, CTRL-7, CTRL-8,
  119.   CTRL-9, CTRL-0, keyboard, keypress
  120.   */
  121.  
  122.  
  123.  
  124.   DISCLAIMER: You have the right to use this technical information
  125.   subject to the terms of the No-Nonsense License Statement that
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1155
  141.   VERSION  :  3.1
  142.        OS  :  DOS
  143.      DATE  :  November 4, 1992                         PAGE  :  3/3
  144.  
  145.     TITLE  :  Detecting unusual keystrokes and key combinations.
  146.  
  147.  
  148.  
  149.  
  150.   you received with the Borland product to which this information
  151.   pertains.
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.